package hydrap2p.gui.commands;

import org.apache.thrift.TException;

import hydrap2p.gui.DetailsPanel;
import hydrap2p.gui.FileTransferPanel;
import hydrap2p.gui.GUIDataHandler;
import hydrap2p.gui.GUIDownloadListing;

public class Cmd_DetailsPanel_RefreshDetails implements Command {

	@Override
	public void execute() {
		int row = FileTransferPanel.getInstance().getTable().getSelectedRow();
		
		if (row < 0){
			DetailsPanel.getInstance().refreshDetails(null);
		}else{
			GUIDownloadListing gdl = null;
			try{
				int tableRow = FileTransferPanel.getInstance().getTable().convertRowIndexToModel(row);
				int realRow = FileTransferPanel.getInstance().getIndexMappings().get(tableRow);
				gdl = GUIDataHandler.getInstance().getDownloadListing().get(realRow);
			}catch(IndexOutOfBoundsException ioobe){
				System.out.println("Model-table indexing discrepancy");
			}
			DetailsPanel.getInstance().refreshDetails(gdl);
		}
	}

	@Override
	public String getCommand() {
		return this.getClass().getSimpleName();
	}

	@Override
	public void unexecute() {
		// TODO Auto-generated method stub

	}

}
